package io.renren.service.impl;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import io.renren.dao.SysProductDao;
import io.renren.entity.SysProductEntity;
import io.renren.service.SysProductService;
import io.renren.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;



@Service("sysProductService")
public class SysProductServiceImpl extends ServiceImpl<SysProductDao, SysProductEntity> implements SysProductService {

    @Autowired
    private SysProductDao sysProductDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysProductEntity> page = this.page(
                new Query<SysProductEntity>().getPage(params),
                new QueryWrapper<SysProductEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils retailOptionalProducts(Map<String, Object> params) {
        IPage<SysProductEntity> page = new LambdaQueryChainWrapper<>(sysProductDao)
                .eq(SysProductEntity::getStockAllowed, 1)
                .page(new Query<SysProductEntity>().getPage(params));

        return new PageUtils(page);
    }

}
